package com.servcice.impl;

import com.dao.ChartDao;
import com.dao.ChartRedisDao;
import com.dto.BaseDto;
import com.dto.dataenum.MessageEnum;
import com.entity.Chart;

import com.servcice.ChartService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service("chartService")
public class ChartServiceImpl implements ChartService {

    @Resource(name="chartRedisDao")
    private ChartRedisDao chartRedisDao;

    public void setChartDao(ChartDao chartDao)
    {
        this.chartRedisDao = chartRedisDao;
    }

    public void add(Chart chart){
        chartRedisDao.add(chart);
    }

    public void delete(String id){
        chartRedisDao.delete(id);
    }

    @Override
    public Chart get(String id) {
        return null;
    }

    public BaseDto<Chart> getCharts(String typeName)
    {
        List<Chart> charts = chartRedisDao.getCharts(typeName);
        int size = charts.size();
        MessageEnum messageEnum = size>0? MessageEnum.SELECT_CHART_SUCCESS:MessageEnum.SELECT_CHART_FAIL;
        BaseDto<Chart> dto = new BaseDto<>(messageEnum,charts);
        return dto;
    }

}